package demo3;

// 进程类，表示系统中的进程
class Process {
    private int id; // 进程ID
    private int[] max; // 最大需求向量
    private int[] allocation; // 已分配资源向量
    private int[] need; // 需求向量

    public Process(int id, int n) {
        this.id = id;
        max = new int[n];
        allocation = new int[n];
        need = new int[n];
    }

    // 计算需求向量: need = max - allocation
    public void calculateNeed() {
        for (int i = 0; i < need.length; i++) {
            need[i] = max[i] - allocation[i];
        }
    }

    public int getId() {
        return id;
    }

    public int[] getMax() {
        return max;
    }

    public void setMax(int[] max) {
        this.max = max;
    }

    public int[] getAllocation() {
        return allocation;
    }

    public void setAllocation(int[] allocation) {
        this.allocation = allocation;
    }

    public int[] getNeed() {
        return need;
    }

    public void display() {
        System.out.println("进程 " + id + ":");
        System.out.print("  最大需求: ");
        for (int m : max) System.out.print(m + " ");
        System.out.println();
        System.out.print("  已分配:   ");
        for (int a : allocation) System.out.print(a + " ");
        System.out.println();
        System.out.print("  需求:     ");
        for (int n : need) System.out.print(n + " ");
        System.out.println();
    }
}